import http from '@/utils/http'

export interface RequestUploadFileChunk {
  /** 文件名 */
  name: string
  /** chunk 哈希值 */
  hash: string
  /** chunk 下标 */
  index: number
  /** chunk 总数 */
  total: number
  /** 文件大小 */
  size: number
  chunk: Blob
}

export function uploadFile(data: RequestUploadFileChunk) {
  const formData = new FormData()
  formData.append('name', data.name)
  formData.append('hash', data.hash)
  formData.append('size', String(data.size))
  formData.append('index', String(data.index))
  formData.append('total', String(data.total))
  formData.append('chunk', data.chunk, data.name)

  return http.post('upload/file', formData)
}
